from base import Yaml, Path
from page import Page


class Login(Page):
    """
    登录页面
    """
    __config = Yaml.get_config_as_dict(Path.get_actual_path_by_current_file(__file__, "../login.yaml"))["Login"]

    def login_page(self, account, password, second=None):
        """
        前台登录
        :param account:账号
        :param password:密码
        :param second:默认等待时间2秒
        :return:
        """
        driver = self._driver
        driver.type(self.__config["LOCATION_ACCOUNT"], account)
        driver.type(self.__config["LOCATION_PASSWORD"], password)
        driver.click(self.__config["LOGIN_BUTTON"])
        self.log("[%s] 使用账号 %s 密码 %s 进行前台登录" % (__name__, account, password))
        # driver.forced_wait(second)

    def get_error_tips(self):
        """
        错误提示
        :return:
        """
        error_tips = self.driver.get_explicitly_wait_element_text(self.__config["PROMPT_LOCATION"])
        self.log('错误提示信息获取成功')
        return error_tips